class CanvasHelper {
  constructor(canvasId, canvas, ctx) {
    this.canvasId = canvasId;
    this.canvas = canvas;
    this.ctx = ctx;
  }

  loadImage(url) {
    return new Promise((resolve, _reject) => {
      console.log(`load image url:${url}`);
      const img = this.canvas.createImage();
      img.src = url;
      img.onload = () => resolve(img);
    });
  }

  draw(flag) {
    console.log(this.ctx);
    console.log(this.ctx.draw);
    return new Promise((resolve, _reject) => {
      console.log(this.ctx.draw);
      this.ctx.draw(flag, resolve);
    });
  }

  saveCanvasToTempFile() {
    return new Promise((resolve, reject) => {
      wx.canvasToTempFilePath({
        canvasId: this.canvasId,
        success: resolve,
        fail: reject,
      });
    });
  }
}

module.exports = CanvasHelper;
